package com.learn.springcloud.sleuthservicedatabase.controller;

import com.learn.springcloud.sleuthservicedatabase.bean.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Time : 2018/8/16 16:00
 * @Version : 1.0
 */
@RestController
public class HelloController {

    List<User> users = Arrays.asList(new User("aaa", 10),
            new User("bbb", 11),
            new User("ccc", 12),
            new User("ddd", 13),
            new User("eee", 14));

    @RequestMapping("/sleuth/service/database/test1/{name}")
    public String sayHello(@PathVariable String name) {
        System.out.println("database : " + name);
        User user = users.stream().filter(t -> name.equals(t.getName()))
                .findFirst()
                .orElse(new User("no this user", 0));
        return "hello, " + user.toString();
    }

}
